package com.itheima.dao;

import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface RoleDao {
    @Select("select * from t_role where id in (select role_id from t_user_role where user_id=#{userId})")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id",property = "permissions",many = @Many(select = "com.itheima.dao.PermissionDao.findByRoleId"))
    })
    public Set<Role> findByUserId(Integer userId);

    @Select("select * from t_role")
    List<Role> findAll();

    @Select("select * from t_role where id in (select role_id from t_user_role where user_id=#{userId})")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "permissions",column = "id",many=@Many(select = "com.itheima.dao.PermissionDao.findByRoleId"))
    })
    Set<Role> findRoleWithPermissionByUserId(Integer userId);

    @Select("select * from t_role where id in (select role_id from t_user_role where user_id=#{userId})")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "menus",column = "id",many=@Many(select = "com.itheima.dao.MenuDao.findAllParentMenu"))
    })
    Set<Role> findRoleWithMenuByUserId(Integer userId);
}
